package com.example.fuxi;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@SpringBootApplication
@MapperScan("com.example.fuxi.dao")
public class FuxiApplication {

    public static void main(String[] args) {
        SpringApplication.run(FuxiApplication.class, args);
    }

    // 跨域请求
    @Bean
    public CorsFilter corsFilter() {
        final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        final CorsConfiguration corsConfiguration = new CorsConfiguration();
//        corsConfiguration.setAllowCredentials(true);
        corsConfiguration.addAllowedHeader("*"); //允许所有的头
        corsConfiguration.addAllowedOrigin("*"); // 允许所有的源
        corsConfiguration.addAllowedMethod("*"); // 允许所有的方法
        source.registerCorsConfiguration("/**", corsConfiguration); //  所有的路径
        return new CorsFilter(source);
    }
}
